#Requires AutoHotkey v2.0

global Browser := ""            ;当前运行的浏览器
global DefaultBrowser := ""     ;默认运行的浏览器是Browser的切换参考
global NewPage := false         ;浏览器新窗口运行的开关

;切换默认浏览器
switchBrowsers(bro) {
  global Browser := OnlyInput.switchParameter(Map("firefox", "firefox.exe ", "chrome", "chrome.exe ", "msedge", "msedge.exe "), OnlyInput.parameter)
}

;用新窗口打开
newWindowBrowserRun(add) {
  global Browser
  if (Browser = "firefox.exe ") {
    run("firefox.exe -new-window " . add)
  } else if (Browser) {
    run(Browser . add . " --new-window", , "Max")
  } else {
    run("chrome.exe " . add . " --new-window", , "Max")
  }
}

;指定运行的浏览器
specificBrowserRun(add) {
  global Browser
  global DefaultBrowser
  global VideoPage
  global NewPage
  if SubStr(add, 1, 4) = "Http" {
    if (WinActive(VideoPage) or NewPage) {
      newWindowBrowserRun(add)
    } else if Browser {
      Run(Browser . add)
    } else {
      run add
    }
  } else {
    run add
  }
  SetTimer(()=>Browser:=DefaultBrowser, -100)
}

;指定这一次运行的浏览器
useFirefoxRun() {
  global Browser := "firefox.exe "
}

useChromeRun() {
  global Browser := "chrome.exe "
}

useEdgeRun() {
  global Browser := "msedge.exe "
}


;用浏览器新窗口打开
openInBrowserNewPage() {
  global
  NewPage := true
  SetTimer(() => NewPage := false, -1000)
}

;重新打开当前页面
reopenCurrentWeb() {
  copy := A_Clipboard
  A_Clipboard := ""
  SendEvent "{Esc}"
  SendEvent "^{l}"
  SendEvent "^{c}"
  SendEvent "{Esc}"
  if ClipWait(2) {
    send "^{w}"
    specificBrowserRun(A_Clipboard)
  }
  A_Clipboard := copy
}